var cc__awaiter = __awaiter;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var def_Pool = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
  }
  return babel_createClass(_ctor, null, [{
    key: "poolMap",
    get() {
      return this._poolMap;
    }
  }, {
    key: "prefabMap",
    get() {
      return this._prefabMap;
    }
  }, {
    key: "get",
    value: function get(e) {
      return cc__awaiter(this, undefined, undefined, /* */babel_regeneratorRuntime().mark(function _callee2() {
        var t;
        return babel_regeneratorRuntime().wrap(function _callee2$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                t = this._poolMap.get(e);
                if (!(t && t.size() > 0)) {
                  _context3.next = 5;
                  break;
                }
                _context3.t0 = t.get();
                _context3.next = 16;
                break;
              case 5:
                if (!this._prefabMap.has(e)) {
                  _context3.next = 9;
                  break;
                }
                _context3.t1 = cc.instantiate(this._prefabMap.get(e));
                _context3.next = 15;
                break;
              case 9:
                _context3.next = 11;
                return this.getFromRes(e);
              case 11:
                _context3.t2 = _context3.sent;
                if (_context3.t2) {
                  _context3.next = 14;
                  break;
                }
                _context3.t2 = null;
              case 14:
                _context3.t1 = _context3.t2;
              case 15:
                _context3.t0 = _context3.t1;
              case 16:
                return _context3.abrupt("return", _context3.t0);
              case 17:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee2, this);
      }));
    }
  }, {
    key: "put",
    value: function put(e, t) {
      var n = this._poolMap.get(e);
      if (!n) {
        n = new cc.NodePool();
        this._poolMap.set(e, n);
      }
      n.put(t);
    }
  }, {
    key: "getFromRes",
    value: function getFromRes(e) {
      return cc__awaiter(this, undefined, undefined, /* */babel_regeneratorRuntime().mark(function _callee3() {
        var t;
        return babel_regeneratorRuntime().wrap(function _callee3$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                _context4.next = 2;
                return $2BundleManager.default.getInstance().loadPrefabSync(e);
              case 2:
                t = _context4.sent;
                return _context4.abrupt("return", t ? (t.addRef(), this._prefabMap.set(e, t), cc.instantiate(t)) : (console.error("对象池引用失败！"), null));
              case 4:
              case "end":
                return _context4.stop();
            }
          }
        }, _callee3, this);
      }));
    }
  }, {
    key: "release",
    value: function release(e) {
      var t = this._prefabMap.get(e);
      if (t) {
        t.decRef();
        this._prefabMap.delete(e);
      }
    }
  }]);
}();
exports.default = def_Pool;
def_Pool._poolMap = new Map();
def_Pool._prefabMap = new Map();